﻿@Imports JertiFramework
@ModelType IEnumerable(Of SchoolClick.Database.NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)
@Code
    Dim grid = New JFGridReadOnly(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)("Notas de las actividades evaluativas"),
        viewCont As JFViewDataContainer(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO),
        viewSubCont As JFViewDataContainer(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO),
        retNota As String,
        NotaProm As Decimal = 0
    
    'Primero cargamos las actividades EDITABLES
    For Each ACT_EDIT In Model.Where(Function(ae) ae.NIVEL = 0 And IsNothing(ae.NOTA))
        viewCont = New JFViewDataContainer(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(New ViewDataDictionary(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(New ViewDataDictionary(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(ACT_EDIT)))
        grid.AddFieldsFor(New HtmlHelper(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(Me.ViewContext, viewCont)) _
            .SetTitulo(String.Format("{0} ({1}%)", ACT_EDIT.ACTIVIDAD, ACT_EDIT.PORCENT)) _
            .SetValue(Function(s) s.NOTA) _
            .SetOptions(New JFOptionsFieldsReadOnly().SetHTMLAttributesDisplay(New With {.style = "color: #6D6D6D; font-weight: bold;"}) _
                                                     .SetHTMLAttributesValue(New With {.style = "color: #023D77; text-align: center; padding: 2px 12px;"}))
        For Each SUBACT In Model.Where(Function(ae) ae.NIVEL = 1 And ae.ABREVIACION = ACT_EDIT.ABREVIACION)
            viewSubCont = New JFViewDataContainer(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(New ViewDataDictionary(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(New ViewDataDictionary(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(SUBACT)))
            retNota = If(IsNothing(SUBACT.NOTA), String.Empty, If(SUBACT.NOTA < 6, String.Format("<span class=""sc-nota-reprobada"" >{0}</span>", SUBACT.NOTA), SUBACT.NOTA))
            NotaProm += (SUBACT.NOTA.Value * (SUBACT.PORCENT / 100))
            
            grid.AddFieldsFor(New HtmlHelper(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(Me.ViewContext, viewSubCont)) _
                .SetTitulo(String.Format("{0} ({1}%)", SUBACT.ACTIVIDAD, SUBACT.PORCENT)) _
                .SetValue(retNota) _
                .SetOptions(New JFOptionsFieldsReadOnly().SetHTMLAttributesDisplay(New With {.style = "color: #6D6D6D; padding-left: 25px;"}) _
                                                         .SetHTMLAttributesValue(New With {.style = "color: #023D77; text-align: center; padding: 2px 12px;"}))
            
        Next
    Next
    
    'Por ultimo cargamos las actividades que no son editables
    For Each ACT_EDIT In Model.Where(Function(ae) ae.NIVEL = 0 And Not IsNothing(ae.NOTA))
        viewCont = New JFViewDataContainer(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(New ViewDataDictionary(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(New ViewDataDictionary(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(ACT_EDIT)))
        retNota = If(IsNothing(ACT_EDIT.NOTA), String.Empty, If(ACT_EDIT.NOTA < 6, String.Format("<span class=""sc-nota-reprobada"" >{0}</span>", ACT_EDIT.NOTA), ACT_EDIT.NOTA))
        grid.AddFieldsFor(New HtmlHelper(Of NOTAS_ACTIVIDADES_ALUMNO_BYPERIODO)(Me.ViewContext, viewCont)) _
            .SetTitulo(String.Format("{0} ({1}%)", ACT_EDIT.ACTIVIDAD, ACT_EDIT.PORCENT)) _
            .SetValue(retNota) _
            .SetOptions(New JFOptionsFieldsReadOnly().SetHTMLAttributesDisplay(New With {.style = "color: #6D6D6D; font-weight: bold;"}) _
                                                     .SetHTMLAttributesValue(New With {.style = "color: #023D77; text-align: center; padding: 2px 12px;"}))
        NotaProm += (ACT_EDIT.NOTA.Value * (ACT_EDIT.PORCENT / 100))
    Next
    
    'Colocamos el total del promedio del periodo
    retNota = If(IsNothing(Math.Round(NotaProm, 2, MidpointRounding.AwayFromZero)), String.Empty, If(Math.Round(NotaProm, 2, MidpointRounding.AwayFromZero) < 6, String.Format("<span class=""sc-nota-reprobada"" >{0}</span>", Math.Round(NotaProm, 2, MidpointRounding.AwayFromZero)), Math.Round(NotaProm, 2, MidpointRounding.AwayFromZero)))
    grid.AddField("Promedio final del periodo", retNota,
                  New JFOptionsFieldsReadOnly().SetHTMLAttributesDisplay(New With {.style = "text-align: left; font-weight: bold; border-top: 1px solid #A0A0A0;background-color: #F5F5F5; color: #6D6D6D;"}
                ).SetHTMLAttributesValue(New With {.style = "text-align: center; font-weight: bold; border-top: 1px solid #A0A0A0; background-color: #F5F5F5; padding: 3px 12px;"})
    )
End Code
<div class="sc-act-eva-notas" style="font-size: 12px;">
    @If Model.Count > 0 Then
        @MvcHtmlString.Create(grid.ToString)    
    Else
        @Html.ErrorInformation("No se encontró ninguna actividad",
                               "Por el momento, no existe ninguna actividad evaluativa para este periodo definida por el profesor.",
                               "ui-icon-alert",
                                "float: left; margin-right: .3em; margin-top:2px;")
    End If
</div>

